<template>
  <div class="integral_My">
    <c-title :hide="false" :text="titlePage"></c-title>
    <div id="background_box">{{ $route.name == "integral_My" ? "我参与消费的分润池" : titlePage + "详情" }}</div>
    <div class="list">
      <div class="integral_My_list" v-for="item in info" :key="item.dividend_pool_id" @click="tapLink(item)">
        <div class="integral_My_list_l" v-if="$route.name == 'integral_My'">{{ item.name }}</div>
        <div class="integral_My_list_l" v-else>{{ item.time }}</div>
        <div class="integral_My_list_r">
          <div class="txt">查看详情</div>
          <i class="iconfont icon-member_right"></i>
        </div>
      </div>
    </div>
    <van-popup round v-model="show" closeable position="bottom" :style="{ height: '60%', background: '#fff' }">
      <div class="popupTitle">{{ popup_Title }}</div>
      <div class="detailBox">
        <div class="detailBox_l">池子待分润总金额</div>
        <div class="detailBox_r">{{ detailInfo.total_value }}</div>
      </div>
      <div class="detailBox">
        <div class="detailBox_l">昨日新增金额</div>
        <div class="detailBox_r">{{ detailInfo.add_value }}</div>
      </div>
      <div class="detailBox">
        <div class="detailBox_l">今日分润金额</div>
        <div class="detailBox_r">{{ detailInfo.value }}</div>
      </div>
      <div class="detailBox">
        <div class="detailBox_l">今日分润份数</div>
        <div class="detailBox_r">{{ detailInfo.count }}</div>
      </div>
      <div class="detailBox">
        <div class="detailBox_l">今日每份分润金额</div>
        <div class="detailBox_r">{{ detailInfo.dividend_value }}</div>
      </div>
    </van-popup>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      infoData: {},
      info: [],
      titlePage: "",
      urlstr: "",
      show: false,
      popup_Title: "",
      detailInfo: {},

      isLoadMore: true,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.init();
    if (this.$route.name == "integral_My") {
      this.urlstr = "plugin.project-party.frontend.controllers.index.memberBonusPool";
      this.titlePage = "我的分润池";
      this.getData();
    } else if (this.$route.name == "integral_My_Date") {
      this.urlstr = "plugin.project-party.frontend.controllers.index.memberBonusPoolDate";
      this.getData();
    }
  },
  methods: {
    init() {
      this.page = 1;
      this.isLoadMore = true;
      this.total_page = 0;
      this.info = [];
      this.urlstr = "";
    },
    tapLink(item) {
      if (this.$route.name == "integral_My") {
        this.$router.push(this.fun.getUrl("integral_My_Date", { pool_id: item.dividend_pool_id }));
        return;
      } else {
        this.getDateDetail(item);
      }
    },
    async getDateDetail(item) {
      let _json = {
        time: item.time,
        pool_id: item.dividend_pool_id
      };
      let { data, msg, result } = await $http.post("plugin.project-party.frontend.controllers.index.memberBonusPoolDetail", _json, "");
      if (result) {
        this.detailInfo = data.data;
        this.popup_Title = item.time + "详情";
        this.show = true;
      } else {
        this.$toast(msg);
      }
    },
    async getData() {
      let _json = { page: this.page };
      if (this.$route.name == "integral_My_Date") {
        _json.pool_id = this.$route.params.pool_id;
      }
      let { data, msg, result } = await $http.post(this.urlstr, _json, "");
      if (result) {
        if (this.$route.name == "integral_My") {
          this.info = data.data;
          this.total_page = data.pages;
          this.isLoadMore = true;
        } else {
          this.info = data.data;
          this.total_page = data.pages;
          this.isLoadMore = true;
          if (data.data.length > 0) {
            this.titlePage = data.data[0].dividend_pool_name;
            this.fun.setWXTitle(data.data[0].dividend_pool_name);
          }
        }
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false;
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let _json = { page: this.page };
        if (this.$route.name == "integral_My_Date") {
          _json.pool_id = this.$route.params.pool_id;
        }
        let { data, msg, result } = await $http.post(this.urlstr, _json, "");
        this.isLoadMore = true;
        if (result) {
          this.info = this.info.concat(data.data);
        } else {
          this.$toast(msg);
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
#background_box {
  height: 4rem;
  color: #fff;
  background: linear-gradient(180deg, #f15353 90%, #f5f5f5 100%);
  overflow: hidden;
  text-align: center;
  line-height: 4rem;
}
.popupTitle {
  line-height: 3rem;
  font-size: 1.2rem;
  font-weight: 500;
}
.detailBox {
  margin: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .detailBox_r {
    color: #f15353;
  }
}
.list {
  margin: 1rem 0.5rem;
  overflow: hidden;
  .integral_My_list {
    padding: 1rem 0.5rem;
    border-radius: 0.5rem;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    .integral_My_list_r {
      display: flex;
      align-items: center;
      color: #999;
    }
  }
}
</style>
